//
//  BWMainViewController.swift
//  weibo
//
//  Created by libowen on 16/5/20.
//  Copyright © 2016年 libowen. All rights reserved.
//
import UIKit
import Foundation

class BWMainViewController: UITabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        addChildViewControllers()
        
        let mainTabbar = BWMainTabbar()
        
        mainTabbar.plusBtn.addTarget(self, action: "plusBtnDidClick", forControlEvents: .TouchUpInside)
//        print(tabBar.classForCoder)
        setValue(mainTabbar, forKey: "tabBar")
//        print(tabBar.classForCoder)
    }
    
    @objc private func plusBtnDidClick() {
        print("我被点击了")
    }
    
    private func addChildViewControllers() {
        addChildViewController(BWHomeTableViewController(),title: "首页",imageName: "tabbar_home")
        addChildViewController(BWMessageTableViewController(),title: "消息",imageName: "tabbar_message_center")
        addChildViewController(BWDiscoverTableViewController(),title: "发现",imageName: "tabbar_discover")
        addChildViewController(BWProfileTableViewController(),title: "我的",imageName: "tabbar_profile")
    }
    
    private func addChildViewController(vc: UIViewController, title: String, imageName:String) {
        vc.title = title;
        vc.tabBarItem.image = UIImage(named: imageName)
        
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        vc.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3)
        
        let nav = UINavigationController(rootViewController: vc)

        addChildViewController(nav)
    }
    
    
}

class person: NSObject {
    func haha() {
//        let tab = BWMainViewController()
//        
//        tab.addChildViewControllers()
    }
    
}

























